<template>
  <div>
    <uni-popup ref="popup" type="share" safeArea backgroundColor="#fff">
      <uniPopupElectricCable
        :title="title"
        :data="data"
		    asdbad="22"
        @select="select"
      ></uniPopupElectricCable>
    </uni-popup>
  </div>
</template>

<script>
import uniPopupElectricCable from "@/component/uni-popup-electricCable/uni-popup-electricCable.vue";
export default {
  components: {
    uniPopupElectricCable
  },
  data() {
    return {
      assetCode: "",
      prjId: "",
      labelId: "",
      data: [],
      // true是设计方案，false是乙供清单
      isbsupply: true,
    };
  },
  methods: {
    open(prjId, assetCode, labelId) {
		  this.$refs.popup.open("share");
      this.prjId = prjId;
      this.assetCode = assetCode;
      this.labelId = labelId;
      uni.showLoading({
        title: "加载中",
        mask: true
      });
      uni.request({
        // url:
        //   uni.getStorageSync("url") +
        //   "/pms/app/complete/queryAuxCategoryList?prjId=" +
        //   this.prjId +
        //   "&categoryType=" +
        //   this.assetCode,
        url: uni.getStorageSync("PMS20url") +
          "/api/app/auxMaterial/queryAuxCategoryList?prjId=" +
          this.prjId +
          "&categoryType=" +
          this.assetCode,
        method: "GET",
        dataType: "json",
        timeout: 1000 * 60,
        header: {
          "sysToken": uni.getStorageSync("PMStoken"),
        },
        success: (res) => {
          uni.hideLoading();
          console.log("获取项目列表数据:", res);
          var data = res.data;
          if (data.code == "200") {
            // 筛选出甲供
            const dataA = data.data[0].children.filter(
              (item) => item.isbsupply === "0"
            );
            this.isbsupply = dataA.length !== 0;
            if (this.isbsupply) {
              // 有甲供，只显示甲供
              this.data = dataA;
            } else {
              this.data = data.data[0].children;
            }
            this.$refs.popup.open("share");
			
          } else {
            uni.showModal({
              title: "提示",
                confirmColor: '#eb4b4b',
              content: res?.data?.message || "接口返回错误",
              showCancel: false,
            });
          }
          uni.hideLoading();
          uni.stopPullDownRefresh();
        },
        fail: (e) => {
          console.log(e);
          uni.hideLoading();
          uni.showModal({
            title: "提示",
              confirmColor: '#eb4b4b',
            content: "网络连接异常",
            showCancel: false,
          });
        },
      });
    },
  select(index,catCodeer) {
	  let that=this;
	  console.log("点击了那个",index,catCodeer)
      uni.showLoading({
        title: "加载中",
        mask: true
      });
      uni.request({
        // url:
        //   uni.getStorageSync("url") +
        //   "/pms/app/complete/auxAssignCode?prjId=" +
        //   this.prjId +
        //   "&categoryCode=" +
        //   catCodeer +
        //   "&labelId=" +
        //   this.labelId +
        //   "&isFromPhoto=1&categoryType=" +
        //   this.assetCode,
        url:
        uni.getStorageSync("PMS20url") +
          "/api/app/auxMaterial/auxAssignCode?prjId=" +
          this.prjId +
          "&categoryCode=" +
          catCodeer +
          "&labelId=" +
          this.labelId +
          "&isFromPhoto=1&categoryType=" +
          this.assetCode,
        method: "POST",
        dataType: "json",
        timeout: 1000 * 60,
        header: {
          "sysToken": uni.getStorageSync("PMStoken"),
        },
        success: (res) => {
          uni.hideLoading();
          var data = res.data;
          if (data.code == "200") {
            uni.showToast({
              title: "赋码贴签成功",
              duration: 1000,
            });
            setTimeout(() => {
              that.$refs.popup.close()
			        that.$emit("mylick","4")
            }, 1000);
          } else {
            uni.showModal({
              title: "提示",
              content:
              data.message ,
                confirmColor: '#eb4b4b',
              showCancel: false,
            });
          }
          uni.hideLoading();
          uni.stopPullDownRefresh();
        },
        fail: () => {
          uni.hideLoading();
          uni.showModal({
            title: "提示",
            content: "网络连接异常",
              confirmColor: '#eb4b4b',
            showCancel: false,
          });
        },
      });
    },
  },
  computed: {
    title() {
      return this.isbsupply ? "设计方案" : "外市电电力电缆";
    },
  },
};
</script>
